package com.travelSpring.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.travelSpring.annotation.RequireAdmin;
import com.travelSpring.common.Result;
import com.travelSpring.pojo.entity.Scenic;
import com.travelSpring.pojo.vo.ScenicVO;
import com.travelSpring.service.ScenicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 功能：
 * 作者：卷心菜
 * 日期：2025/4/21 16:36
 */
@RestController
@RequestMapping("/scenic")
@RequireAdmin
public class ScenicController {

    @Autowired
    ScenicService scenicService;

    @GetMapping("/selectAll")
    public Result selectAll() {
        List<Scenic> scenics = scenicService.selectAll();
        return Result.success(scenics);
    }

    @GetMapping("/selectById/{id}")
    public Result selectById(@PathVariable Integer id) {
        Scenic scenic = scenicService.selectById(id);
        return Result.success(scenic);
    }

    @GetMapping("/selectPage")
    public Result selectPage(@RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "8") Integer pageSize,
                             Scenic scenic
                             ){
        IPage<ScenicVO> iPage = scenicService.selectPage(pageNum,pageSize, scenic);
        return Result.success(iPage);
    }

    @PostMapping("/add")
    public Result add(@RequestBody Scenic scenic){
        scenicService.add(scenic);
        return Result.success();
    }

    @PostMapping("/update")
    public Result update(@RequestBody Scenic scenic){
        scenicService.update(scenic);
        return Result.success();
    }

    @PostMapping("/updateBatch")
    public Result updateBatch(@RequestBody List<Scenic> list){
        scenicService.updateBatch(list);
        return Result.success();
    }

    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Integer id){
        scenicService.delete(id);
        return Result.success();
    }

    @DeleteMapping("/deleteBatch")
    public Result deleteBatch(@RequestBody List<Scenic> ids){
        scenicService.deleteBatch(ids);
        return Result.success();
    }
}
